<template>
	<view class="home">
		<navbar></navbar>
		<tab :list="labelList" :tabIndex="tabIndex" @tab="tab"></tab>
		<list class="home-list" :tab="labelList" :activeIndex="activeIndex" @change="change"></list>
		<!-- <view class="scroll">
			<scroll-view class="list-scroll" scroll-y="true">
				<view>
					<view v-for="(item,index) in 100" :key="index">
						1111
					</view>
				</view>
			</scroll-view>
		</view> -->
	</view>
</template>

<script>
	import {mapState} from 'vuex'
	export default {
		data() {
			return {
				title: 'Hello',
				labelList: [],
				tabIndex: 0,
				activeIndex: 0,
			}
		},
		computed:{
			...mapState(['userinfo'])
		},
		watch:{
			userinfo(newVal){
				this.getLabel()
			}
		},
		onLoad() {
			//接收 监听全局的事件
			uni.$on('labelChange',(res) => {
				this.labelList = []
				this.tabIndex = 0
				this.activeIndex = 0
				this.getLabel()
			})
		},
		methods: {
			// 调用云函数
			getLabel() {
				// console.log(this.$api)
				this.$api.get_label(
					// {
					// 	name: 'get_label'
					// }
				).then((res) => {
					let result = res.data
					// console.log(result)
					result.unshift({
						name: "全部"
					})
					this.labelList = result
				})
			},
			//传参
			// tab参数
			tab({
				data,
				index
			}) {
				this.activeIndex = index
				// console.log(data,index)
			},
			// list参数
			change(current) {
				this.tabIndex = current
				// console.log(current)
			}
		}
	}
</script>

<style lang="scss">
	page {
		height: 100%;
		display: flex;
	}

	.home {
		display: flex;
		flex-direction: column;
		flex: 1;

		// overflow: hidden;
		// .scroll{
		// 	flex: 1;
		// 	overflow: hidden;
		// 	box-sizing: border-box;
		// 	.list-scroll{
		// 		height: 100%;
		// 		display: flex;
		// 		flex-direction: column;
		// 	}
		// }
		.home-list {
			flex: 1;
			overflow: hidden;
			height: 100%;
		}
	}
</style>
